using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Build.Framework;

namespace WMVConvert
{
	public class MediaTaskItem: IMediaInfo
	{
		private ITaskItem taskItem;

		public MediaTaskItem(ITaskItem item)
		{
			this.taskItem = item;
		}

		private string GetProperty(string key)
		{
			string value = taskItem.GetMetadata(key);
			if (value == null)
			{
				return string.Empty;
			}
			return value;
		}

		private int GetIntProperty(string key)
		{
			string value = GetProperty(key);
			int castedValue = 0;
			int.TryParse(value, out castedValue);
			return castedValue;
		}

		private long GetLongProperty(string key)
		{
			string value = GetProperty(key);
			long castedValue = 0;
			long.TryParse(value, out castedValue);
			return castedValue;
		}

		private double GetDoubleProperty(string key)
		{
			string value = GetProperty(key);
			double castedValue = 0;
			double.TryParse(value, out castedValue);
			return castedValue;
		}

		#region IMediaInfo Members

		public string SourceFile
		{
			get { return GetProperty("Source"); }
		}

		public string TargetFile
		{
			get { return taskItem.ItemSpec; }
		}

		public int Segment
		{
			get { return GetIntProperty ("Segment"); }
		}

		public double AspectRatio
		{
			get { return GetDoubleProperty("AspectRatio"); }
		}

		public int AudioBitRate
		{
			get { return GetIntProperty("AudioBitRate"); }
		}

		public string AudioCodec
		{
			get { return GetProperty("AudioCodec"); }
		}

		public int AudioCount
		{
			get { return GetIntProperty("AudioCount"); }
		}

		public int Channels
		{
			get { return GetIntProperty("Channels"); }
		}

		public string Format
		{
			get { return GetProperty("Format"); }
		}

		public double FrameRate
		{
			get { return GetDoubleProperty("FrameRate"); }
		}

		public int Height
		{
			get { return GetIntProperty("Height"); }
		}

		public int Width
		{
			get { return GetIntProperty("Width"); }
		}

		public long PlayTime
		{
			get { return GetLongProperty("PlayTime"); }
		}

		public int Resolution
		{
			get { return GetIntProperty("Resolution"); }
		}

		public long SamplingRate
		{
			get { return GetLongProperty("SamplingRate"); }
		}

		public int TextCount
		{
			get { return GetIntProperty("TextCount"); }
		}

		public int VideoBitRate
		{
			get { return GetIntProperty("VideoBitRate"); }
		}

		public int VideoPeakBitRate
		{
			get { return GetIntProperty("VideoPeakBitRate"); }
		}

		public string VideoCodec
		{
			get { return GetProperty("VideoCodec"); }
		}

		public int VideoCount
		{
			get { return GetIntProperty("VideoCount"); }
		}

		public int Start
		{
			get { return GetIntProperty("Start"); }
		}

		public int End
		{
			get { return GetIntProperty("End"); }
		}

		public string Title
		{
			get { return GetProperty("Title"); }
		}

		public string Description
		{
			get { return GetProperty("Description"); }
		}

		public string Author
		{
			get { return GetProperty("Author"); }
		}

		public string Copyright
		{
			get { return GetProperty("Copyright"); }
		}

		#endregion
	}
}
